package com.ccnu.JobHub.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccnu.JobHub.mapper.ViewPostMapper;
import com.ccnu.JobHub.model.database.ViewPost;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ViewPostService extends ServiceImpl<ViewPostMapper, ViewPost> {

    private final ViewPostMapper viewPostMapper;

    public ViewPostService(ViewPostMapper viewPostMapper) {
        this.viewPostMapper = viewPostMapper;
    }

    /**
     * 搜索升学贴
     * @param search 搜索内容
     * @param page 当前页码
     * @param pageSize 页面大小
     * @return 一个list
     */
    public List<ViewPost> searchEnrollmentPost(String search, Integer page, Integer pageSize, String type) {
        int offset = 0;
        if (page != 0){
            offset = (page-1)*pageSize;
        }
        if (type.equals("time")){
            type = "updated_at";
        }
        else if (type.equals("hot")){
            type = "like_num";
        }
        return viewPostMapper.searchEnrollmentPost(search, offset, pageSize, type);
    }

    /**
     * 显示升学贴
     * @param page 当前页码
     * @param pageSize 页面大小
     * @return 一个list
     */
    public List<ViewPost> listEnrollmentPost(Integer page, Integer pageSize ,String type) {
        int offset = 0;
        if (page != 0){
            offset = (page-1)*pageSize;
        }
        if (type.equals("time")){
            type = "updated_at";
        }
        else if (type.equals("hot")){
            type = "like_num";
        }
        return viewPostMapper.listEnrollmentPost(offset, pageSize, type);
    }

    /**
     * 搜索就业贴
     * @param search 搜索内容
     * @param page 当前页码
     * @param pageSize 页面大小
     * @return 一个list
     */
    public List<ViewPost> searchJobPost(String search, Integer page, Integer pageSize, String type) {
        int offset = 0;
        if (page != 0){
            offset = (page-1)*pageSize;
        }
        if (type.equals("time")){
            type = "updated_at";
        }
        else if (type.equals("hot")){
            type = "like_num";
        }
        return viewPostMapper.searchJobPost(search, offset, pageSize, type);
    }

    /**
     * 显示升学贴
     * @param page 当前页码
     * @param pageSize 页面大小
     * @return 一个list
     */
    public List<ViewPost> listJobPost(Integer page, Integer pageSize,String type) {
        int offset = 0;
        if (page != 0){
            offset = (page-1)*pageSize;
        }
        if (type.equals("time")){
            type = "updated_at";
        }
        else if (type.equals("hot")){
            type = "like_num";
        }
        return viewPostMapper.listJobPost(offset, pageSize,type);
    }
}
